/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author Алексей
 */

package ru.amse.podolsky.fractalarch;
import java.awt.image.*;
import java.io.*;

public class GraphicOutput {
    
    //Constants
    private static final int domenSize = IParams.DOMEN_SIZE;
    
    public static void drowToFile(Domen[] domens, int number) throws IOException{
        prepare();
        String path = "block" + number + ".bmp";           
        File file = new File(path);
        file.createNewFile();
        ImagesIO out = new ImagesIO(path);
        BufferedImage buff = new BufferedImage(160,160,BufferedImage.TYPE_INT_RGB);
        
        for(int i = 0; i < domens.length; ++i){
            int x = (i % 4) * 40;
            int y = (i / 4) * 40;
            for(int k = 0; k < domenSize; ++k){
                for(int n = 0; n < domenSize; ++n){
                    int color = (domens[i].getPixel(k, n) << 16) + (domens[i].getPixel(k, n) << 8) + domens[i].getPixel(k, n);
                    buff.setRGB(x + k * 4, y + n * 4, color);
                    buff.setRGB(x + k * 4 + 1, y + n * 4, color);
                    buff.setRGB(x + k * 4 + 2, y + n * 4, color);
                    buff.setRGB(x + k * 4 + 3, y + n * 4, color);
                    buff.setRGB(x + k * 4, y + n * 4 + 1, color);
                    buff.setRGB(x + k * 4 + 1, y + n * 4 + 1, color);
                    buff.setRGB(x + k * 4 + 2, y + n * 4 + 1, color);
                    buff.setRGB(x + k * 4 + 3, y + n * 4 + 1, color);
                    buff.setRGB(x + k * 4, y + n * 4 + 2, color);            
                    buff.setRGB(x + k * 4 + 1, y + n * 4 + 2, color);
                    buff.setRGB(x + k * 4+ 2, y + n * 4 + 2, color);
                    buff.setRGB(x + k * 4 + 3, y + n * 4 + 2, color);                        
                    buff.setRGB(x + k * 4, y + n * 4 + 3, color);                   
                    buff.setRGB(x + k * 4 + 1, y + n * 4 + 3, color);
                    buff.setRGB(x + k * 4 + 2, y + n * 4 + 3, color);
                    buff.setRGB(x + k * 4 + 3, y + n * 4 + 3, color);                   
                }
            }
        }
        
        out.write(buff);
    }
    
    private static void prepare() throws IOException{
        File file = new File("\\blocks");
        if(!file.exists()){
            file.createNewFile();
        }
    }
}